package hou;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Test09 {

    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException {
        Class c1 = Class.forName("hou.User");

        System.out.println(c1.getName());  //包名+类名
        System.out.println(c1.getSimpleName());  //类名

        //获得所有属性
        Field[] fields = c1.getDeclaredFields();
        for (Field field : fields) {
            System.out.println(field);
        }

        //获得public方法
        Method[] methods = c1.getMethods();
        for (Method method : methods) {
            System.out.println(method);
        }

        //获得指令属性
        Field name = c1.getDeclaredField("name");
        System.out.println(name);

        //获得指定方法
        Method getname = c1.getMethod("getName", null);
        Method setname = c1.getMethod("setName", String.class);
        System.out.println(getname);
        System.out.println(setname);

        //获得指定的构造器
        Constructor[] constructors = c1.getConstructors();
        for (Constructor constructor : constructors) {
            System.out.println(constructor);
        }

        //获得指令构造器
        Constructor constructor = c1.getConstructor(String.class, int.class);
        System.out.println(constructor);
    }
}
